// import { initData } from "../view/ota/constance";
import { SET_INIT_PARAM } from "./type";

export type ParamType = {
  date: string;
  location: Location;
};

export type Location = {
  from: string;
  to: string;
};
export function param(
  state: Partial<ParamType> = {},
  action: { type: string; data: ParamType }
) {
  if (action.type === SET_INIT_PARAM) {
    return {
      ...state,
      ...action.data,
    };
  } else {
    return state;
  }
}

export function setInitParam(data: ParamType) {
  return {
    type: SET_INIT_PARAM,
    data,
  };
}

export const getLocation =
  () =>
  (state: any): Location =>
    state.param.location;
export const getParam =
  () =>
  (state: any): ParamType =>
    state.param;
